// 100. 相同的树
// https://leetcode.cn/problems/same-tree/

/**
示例 1：


输入：p = [1,2,3], q = [1,2,3]
输出：true

示例 2：


输入：p = [1,2], q = [1,null,2]
输出：false

示例 3：


输入：p = [1,2,1], q = [1,1,2]
输出：false

 */

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {boolean}
 */
var isSameTree = function (p, q) {
    if (p === null && q === null) return true;

    if (p === null || q === null) return false;

    if (p.val !== q.val) return false;

    return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
};
